/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-08-08
 * Time: 19:13
 */
public class Test1 {
    public static int min(int[] arr,int x) {
        int sum = 0;
        for(int a : arr) {
            sum += a;
        }
        int target = sum - x;
        if(target < 0) return -1;
        int ret = -1;
        for(int left = 0,right = 0,tmp = 0; right < arr.length; right++) {
            tmp += arr[right];
            while(tmp > target) tmp -= arr[left++];
            if(tmp == target) ret = Math.max(ret,right - left + 1);
        }
        if(ret == -1) return ret;
        else return arr.length - ret;
    }

    public static void main(String[] args) {
        int[] arr = {8828,9581,49,9818,9974,9869,9991,10000,10000,10000,9999,9993,9904,8819,1231,6309};
        int count = min(arr,134365);
        System.out.println(count);
    }
}
